{% extends 'base.html' %}
{% load staticfiles %}
{% load comment_tags %}
{% load likes_tags %}
{% block header_extends %}
    <link rel="stylesheet" href="{% static 'blog/blog.css' %}">
{% endblock %}
{% block nav_blog_active %}
    active
{% endblock %}

{% block title %}
    我的网站
{% endblock %}

{% block content %}
    <div class="container">
        <div class="row">
            {#        博客列表#}
            <div class="col-xs-12 col-sm-8 col-md-9 col-lg-9">
                <div class="panel panel-default">
                    <div class="panel-heading ">
                        {% block blog_list_title %}
                            博客列表
                        {% endblock %}
                    </div>
                    <div class="panel-body">
                        {#page_or_blogs from views.py 13 row #}
                        {% for blog in blogs %}
                            <div class="blog">
                                <h3>
                                    <a href="{% url 'blog_datell' blog.pk %}">
                                        {{ blog.title }}
                                    </a>
                                </h3>
                                <p class="blog-info">
                                    <span class="glyphicon glyphicon-tag" aria-hidden="true"></span>
                                    <a href="{% url 'blogs_with_type' blog.blog_type.pk %}">{{ blog.blog_type }}</a>&nbsp;&nbsp;
                                    <span class="glyphicon glyphicon-time" aria-hidden="true"></span>
                                    {{ blog.created_time|date:"Y-m-d" }}&nbsp;&nbsp;
                                    {#get_read_num方法是models里的函数名：def get_read_num(self):#}
                                    阅读：{{ blog.get_read_num }}&nbsp;&nbsp;
                                    评论：{% get_comment_count blog %}
                                    点赞：{% get_like_count blog %}
                                </p>
                                <p>{{ blog.content|striptags|truncatechars_html:120 |safe }}</p>
                            </div>
                        {% empty %}
                            <div class="blog">
                                <h3>--暂无博客，敬请期待。--</h3>
                            </div>
                        {% endfor %}
                    </div>
                    <div id="panel-footer" class="panel-footer"><p>本页有{{ page_of_blogs|length }}篇博客
                        共有{{ page_of_blogs.paginator.num_pages }}页</p></div>
                </div>
                <div class="paginator">
                    {# 上一页 #}
                    <ul class="pagination">
                        <li>
                            {% if page_of_blogs.has_previous %}
                                <a href="?page={{ page_of_blogs.previous_page_number }}" aria-label="Previous">
                                    <span aria-hidden="true">&laquo;</span>
                                </a>
                            {% else %}
                                <span aria-hidden="true">&laquo;</span>
                            {% endif %}

                        </li>
                        {# 全部页码 #}

                        {% for page_num in page_range %}
                            {# 注：如果当前页等于页码激活按钮 #}
                            {% if page_num == page_of_blogs.number %}
                                <li class="active"><span>{{ page_num }}</span></li>
                            {% else %}
                                {% if page_num == '...' %}
                                    <li><span>{{ page_num }}</span></li>
                                {% else %}
                                    <li><a href="?page={{ page_num }}">{{ page_num }}</a></li>
                                {% endif %}
                            {% endif %}
                        {% endfor %}
                        {# 下一页 #}
                        <li>
                            {% if page_of_blogs.has_next %}
                                <a href="?page={{ page_of_blogs.next_page_number }}" aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                </a>
                            {% else %}
                                <span aria-hidden="true">&raquo;</span>
                            {% endif %}
                        </li>
                    </ul>
                </div>
            </div>
            {#        博客分类#}
            <div class="hidden-xs col-sm-4 col-md-3 col-lg-3">
                <div class="panel panel-default">
                    <div class="panel-heading">博客分类</div>
                    <div class="panel-body">
                        <ul class="blog-types">
                            {% for blog_type in blog_types %}
                                <li>
                                    <a href="{% url 'blogs_with_type' blog_type.pk %}">
                                        {{ blog_type.type_name }} ({{ blog_type.blog_count }})
                                    </a>
                                </li>
                            {% empty %}
                                <li>暂无分类</li>
                            {% endfor %}
                        </ul>
                    </div>
                </div>
                <div class="panel panel-default">
                    <div class="panel-heading">
                        日期归档
                    </div>
                    <div class="panel-body">
                        <ul>
                            {% for blog_date,blog_count in blog_dates.items %}
                                <li>
                                    <a href="{% url 'blogs_with_date' blog_date.year blog_date.month %}">
                                        {{ blog_date|date:"Y年m月" }}({{ blog_count }})
                                    </a>
                                </li>
                            {% endfor %}
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>

{% endblock %}